package com.djnt.catering;

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;

import com.djnt.catering.database.HotNews;
import com.djnt.catering.sales_promotion.SalesPromotionListAdapter;

public class MainTuijian1Activity extends ListActivity {

	protected static final int CITY_SEARCH = 0;
	protected static final String TAG = "MainActivity";
	private Button index_btnCity;

	class GridItem {
		public GridItem(int t, int i, OnClickListener l) {
			// TODO Auto-generated constructor stub
			resTextID = t;
			resImageID = i;
			listen = l;
		}

		public int resTextID;
		public int resImageID;
		public OnClickListener listen;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		Cursor c = this.getContentResolver().query(HotNews.CONTENT_URI, null,
				null, null, null);
		setListAdapter(new SalesPromotionListAdapter(this, R.layout.sales_promotion_user_view, c));

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		switch (requestCode) {
		case CITY_SEARCH:
			if (data != null) {
				String t = data.getStringExtra(Settings.Persist.CITY_NAME);
				if (!TextUtils.isEmpty(t) && !t.equals(index_btnCity.getText())) {
					index_btnCity.setText(t);
					SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(this);
					SharedPreferences.Editor e = mSettings.edit();
					e.putString(Settings.Persist.CITY_NAME, t);
					e.commit();
				}
			}
			return;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}

}
